import { useState, useEffect } from 'react';

const Weather = () => {
    const [weather, setWeather] = useState(null);

    useEffect(() => {
        // 天气数据的 API
        fetch('https://api.weacba.com/v1/current.json?key=PvUUlo4XtdyQcQSsc&q=London')
            .then(response => response.json())
            .then(data => setWeather(data));
    }, []);

    if (!weather) {
        return <div>获取失败...</div>;
    }

    return (
        <div>
            <h2>Weather in {weather.location.name}</h2>
            <p>Temperature: {weather.current.temp_c}°C</p>
            <p>Condition: {weather.current.condition.text}</p>
        </div>
    );
};

export default Weather;